package com.yong.sbd.biz.mp.controller;

import com.yong.sbd.biz.mp.entity.SysUserRole;
import com.yong.sbd.biz.mp.service.SysUserRoleService;
import com.yong.sbd.common.beans.response.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户角色关联控制器
 *
 * @author Kang Yong
 * @date 2025/10/27
 * @since 1.0.0
 */
@RestController
@RequestMapping("/user-role")
@RequiredArgsConstructor
public class SysUserRoleController {
    
    private final SysUserRoleService sysUserRoleService;
    
    /**
     * 查询所有用户角色关联
     *
     * @return {@link R<List<SysUserRole>>}
     */
    @GetMapping("/list")
    public R<List<SysUserRole>> list() {
        return R.success(sysUserRoleService.list());
    }
    
    /**
     * 根据ID查询用户角色关联
     *
     * @param id 用户角色关联ID
     * @return {@link R<SysUserRole>}
     */
    @GetMapping("/{id}")
    public R<SysUserRole> getById(@PathVariable Long id) {
        return R.success(sysUserRoleService.getById(id));
    }
    
    /**
     * 添加用户角色关联
     *
     * @param sysUserRole 用户角色关联信息
     * @return {@link R<Boolean>}
     */
    @PostMapping
    public R<Boolean> save(@RequestBody SysUserRole sysUserRole) {
        return R.success(sysUserRoleService.save(sysUserRole));
    }
    
    /**
     * 更新用户角色关联
     *
     * @param sysUserRole 用户角色关联信息
     * @return {@link R<Boolean>}
     */
    @PutMapping
    public R<Boolean> update(@RequestBody SysUserRole sysUserRole) {
        return R.success(sysUserRoleService.updateById(sysUserRole));
    }
    
    /**
     * 删除用户角色关联
     *
     * @param id 用户角色关联ID
     * @return {@link R<Boolean>}
     */
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable Long id) {
        return R.success(sysUserRoleService.removeById(id));
    }
}